//  全局请求
const requestInterceptor = (url: string, options: RequestInit) => {
  return {
    url,
    options: {
      ...options,
      headers: {
        'Content-Type': 'application/json;charset=UTF-8'
      }
    }
  }
}

// 全局响应拦截
const responseInterceptor = (response: Response, options: ResponseInit) => {
  return response
}

// 错误处理
const errorHandler = (err: string) => {
  throw new Error(err)
}

export const request  = {
  timeout: 1000,
  errorHandler,
  requestInterceptor: [requestInterceptor],
  responseInterceptor: [responseInterceptor],
}
